﻿using System;
using System.Windows.Forms;
using Telerik.WinControls.UI.Data;

namespace FSO
{
    public partial class UserControlSearchMain : UserControl
    {

        public UserControlSearchMain()
        {
            InitializeComponent();

            foreach (Telerik.WinControls.UI.RadListDataItem item in FormHelper.dataItems)
            {
                radDropDownListObjects.Items.Add(item);
            }           
        }

        private void radDropDownListObjects_SelectedIndexChanged(object sender, PositionChangedEventArgs e)
        {
            panelSearch.Controls.Clear();

            if (radDropDownListObjects.SelectedItem.Value != null)
            {
                switch ((ObjctTypeEnum)radDropDownListObjects.SelectedItem.Value)
                {
                    case ObjctTypeEnum.INVOICE_IN:
                        panelSearch.Controls.Add(new UserControlSearchInvoiceIn() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.PAYMENT_OUT:
                        panelSearch.Controls.Add(new UserControlSearchPayOut() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.CONTRACT:
                        panelSearch.Controls.Add(new UserControlSearchContract() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.ORGANIZATION:
                        panelSearch.Controls.Add(new UserControlSearchOrganization() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.CALENDAR_PLAN:
                        panelSearch.Controls.Add(new UserControlSearchCalendarPlan() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.COST_PROTOCOL:
                        panelSearch.Controls.Add(new UserControlSeachCostProtocol(){Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true}); break;
                    case ObjctTypeEnum.INVOICE_OUT:
                        panelSearch.Controls.Add(new UserControlSearchInvoiceOut(){Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true});break;
                    case ObjctTypeEnum.PAYMENT_IN:
                        panelSearch.Controls.Add(new UserControlSearchPaymentIn(){Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true});break;
                    case ObjctTypeEnum.DIRECT:
                        panelSearch.Controls.Add(new UserControlSearchDirect() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.GUILD_BILL:
                        panelSearch.Controls.Add(new UserControlSearchGuildBill() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    case ObjctTypeEnum.VAT_INVOICE:
                        panelSearch.Controls.Add(new UserControlSearchVatInvoice() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = true }); break;
                    default:
                        break;
                }
            }
            
        }

        private void radButtonRefresh_Click(object sender, EventArgs e)
        {
            foreach (Control Cntrl in panelSearch.Controls)
            {
                if (Cntrl is InterfaceSearchControl)
                {
                    (Cntrl as InterfaceSearchControl).RefreshList();
                }
            }
        }
    }
}
